#pragma once

#include "includeBase.h"

#include "core/AppContext.h"
#include "utils/QtUtil.h"

class BaseAction : public QAction
{
public:
    BaseAction(
        const QString& name,
        const QString& text,
        QKeySequence* shortcut = nullptr,
        const QIcon& icon = QIcon()
    )
        : QAction(AppContext::mainWindow())
    {
        this->setObjectName(name);
        this->setText(text);
        if (shortcut) {
            this->setShortcut(*shortcut);
        }
        // if (icon) {
        this->setIcon(icon);
        //}
        connect(this, &QAction::triggered, this, &BaseAction::doAction);
    }

    void showMe()
    {
        QMessageBox::information(
            AppContext::mainWindow(), AppContext::ProductName(), this->text()
        );
    }

    virtual void execute() { showMe(); }

    void showErrorMessageBox(std::exception& e)
    {
        QMessageBox::critical(
            AppContext::mainWindow(), AppContext::ProductName(), e.what()
        );
    }

    void showErrorMessageBox(const QString& message)
    {
        QMessageBox::critical(
            AppContext::mainWindow(), AppContext::ProductName(), message
        );
    }

public slots:
    void doAction() { execute(); }
};
